package teach.shuji.java12.system.service.impl;

import cn.hutool.Hutool;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import teach.shuji.java12.common.CommonResult;
import teach.shuji.java12.common.NoDataCommonResult;
import teach.shuji.java12.system.dto.roles.GetUserByRoleQuery;
import teach.shuji.java12.system.dto.roles.RoleAddDto;
import teach.shuji.java12.system.dto.roles.RoleListQuery;
import teach.shuji.java12.system.entity.Role;
import teach.shuji.java12.system.entity.User;
import teach.shuji.java12.system.mapper.RoleMapper;
import teach.shuji.java12.system.mapper.UserMapper;
import teach.shuji.java12.system.service.RoleService;

import java.util.List;

//5. 写服务实现，如果要操作多个表，就引入多个mapper
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    RoleMapper roleMapper;

    @Autowired
    UserMapper userMapper;

    /**
     * @param role
     * @return
     */
    @Override
    public NoDataCommonResult add(RoleAddDto role) {
        Role entity = BeanUtil.toBean(role, Role.class); //采用 hutool里的工具类，简化类型转换

        entity.setCreateTime(DateTime.now().toLocalDateTime());
        entity.setDelFlag('0');
        entity.setCreateBy("取当前登录人");

        roleMapper.insert(entity);
        return new NoDataCommonResult();
    }

    /**
     * @param role
     * @return
     */
    @Override
    public NoDataCommonResult edit(RoleAddDto role) {
       return new NoDataCommonResult();
    }

    /**
     * @param id
     * @return
     */
    @Override
    public NoDataCommonResult delete(long id) {
        return new NoDataCommonResult();
    }

    /**
     * @param query
     * @return
     */
    @Override
    public CommonResult<List<Role>> list(RoleListQuery query) {
        return new CommonResult<List<Role>>();
    }

    /**
     * @param id
     * @return
     */
    @Override
    public CommonResult<List<User>> getUserByRoleId(GetUserByRoleQuery id) {
        return new CommonResult<List<User>>();
    }
}
